package com.itheima.datastructure;

public class E02Leetcode203 {

    public ListNode removeElements(ListNode head, int val){
        // 哨兵节点
        ListNode s = new ListNode(-1, head);
        ListNode p1 = s;
        ListNode p2 = s.next;
        while(p2 != null){
            if(p2.val == val){
                p1.next = p2.next;
                p2 = p2.next;
            }else {
                p1 = p1.next;
                p2 = p2.next;
            }
        }
        return s.next;
    }


}
